
#ifndef _MPI_SYS_H_
#define _MPI_SYS_H_

#include "mpi_lib.h"

#ifdef  __cplusplus
extern "C"
{
#endif

#define MAX_SOURCE_BUFFER_NUM        (4)

#define INTLC_OFF                0    //no progressive to interlacing
#define INTLC_ON                1    //enable progressive to interlacing

/* interlaced VIN encoding, deinterlacing mode */
#define DEINTLC_OFF                0    //encode as field mode
#define DEINTLC_BOB_MODE        1    //encode as BOB frame mode by dropping one field
#define DEINTLC_WEAVE_MODE    2    //encode as WEAVE frame mode by combining two fields

// source buffer id
#define MEDIA_MAIN_BUFFER               (1 << 0)    // encode format flags, can be or'ed, the MEDIA_MAIN_BUFFER macro and etc can be OR'ed
#define MEDIA_2ND_BUFFER                (1 << 1)    // used in SGKS_MEDIA_IOC_SET_SOURCE_BUFFER_FORMAT_EX and etc
#define MEDIA_3RD_BUFFER                (1 << 2)
#define MEDIA_4TH_BUFFER                (1 << 3)

#ifndef ROUND_UP
#define ROUND_UP(x, n)                  (((x)+(n)-1u) & ~((n)-1u))
#endif



enum
{
    SGKS_ENCODE_SOURCE_MAIN_BUFFER         = 0,
    SGKS_ENCODE_SOURCE_SECOND_BUFFER       = 1,
    SGKS_ENCODE_SOURCE_THIRD_BUFFER        = 2,
    SGKS_ENCODE_SOURCE_FOURTH_BUFFER       = 3,
    SGKS_ENCODE_SUB_SOURCE_BUFFER_FIRST    = SGKS_ENCODE_SOURCE_SECOND_BUFFER,
    SGKS_ENCODE_SUB_SOURCE_BUFFER_LAST     = SGKS_ENCODE_SOURCE_FOURTH_BUFFER + 1,
    SGKS_ENCODE_SOURCE_BUFFER_FIRST        = SGKS_ENCODE_SOURCE_MAIN_BUFFER,
    SGKS_ENCODE_SOURCE_BUFFER_LAST         = SGKS_ENCODE_SOURCE_FOURTH_BUFFER + 1,
    SGKS_DECODE_SOURCE_MAIN_BUFFER         = 5,
    SGKS_DECODE_SOURCE_SCREEN_BUFFER       = 6,
    SGKS_DECODE_SOURCE_SCALE_BUFFER        = 7,
    SGKS_ENCODE_SOURCE_MAIN_SCALE_BUFFER   = 8,
};


typedef enum
{
    MIN_WIDTH_IN_STREAM = 160,
    MIN_HEIGHT_IN_STREAM = 90,

    // Resolution limitation for full frame rate mode
    MAX_WIDTH_IN_FULL_FPS = 1920,
    MAX_HEIGHT_IN_FULL_FPS = 1080,
    MIN_WIDTH_IN_FULL_FPS = MIN_WIDTH_IN_STREAM,
    MIN_HEIGHT_IN_FULL_FPS = MIN_HEIGHT_IN_STREAM,
    MIN_H264_ROTATE_WIDTH_IN_FULL_FPS = MIN_WIDTH_IN_STREAM,
    MIN_H264_ROTATE_HEIGHT_IN_FULL_FPS = MIN_HEIGHT_IN_STREAM,

    // Resolution limitation for high MP mode
    MAX_WIDTH_IN_HIGH_MP = 2592,
    MAX_HEIGHT_IN_HIGH_MP = 2048,
    MIN_WIDTH_IN_HIGH_MP = MIN_WIDTH_IN_STREAM,
    MIN_HEIGHT_IN_HIGH_MP = MIN_HEIGHT_IN_STREAM,
    MIN_H264_ROTATE_WIDTH_IN_HIGH_MP = 320,
    MIN_H264_ROTATE_HEIGHT_IN_HIGH_MP = 240,

    // Resolution limitation for CAVLC encoding
    MAX_WIDTH_IN_CAVLC = 1280,
    MAX_HEIGHT_IN_CAVLC = 720,
} RESOLUTION_RESOURCE_LIMIT;

typedef enum
{
    MAX_WIDTH_FOR_1ST = MAX_WIDTH_IN_HIGH_MP,
    MAX_HEIGHT_FOR_1ST = MAX_HEIGHT_IN_HIGH_MP,

    MAX_WIDTH_FOR_2ND = 1920,//720, SH-L
    MAX_HEIGHT_FOR_2ND = 1080,//576,

    MAX_WIDTH_FOR_3RD = 1920,
    MAX_HEIGHT_FOR_3RD = 1080,

    MIN_WIDTH_IN_HD_SDI_FOR_3RD = 1280,
    MIN_HEIGHT_IN_HD_SDI_FOR_3RD = 720,

    MAX_WIDTH_FOR_4TH = 1920,//1280, SH-L
    MAX_HEIGHT_FOR_4TH = 1080,//720,


    PIP_SIZE_ENABLE_THRESHOLD = 320,
} SOURCE_BUFFER_RESOLUTION_LIMIT;


typedef enum
{
    MAX_ZOOM_IN_FACTOR_FOR_1ST = 10,
    MAX_ZOOM_OUT_FACTOR_FOR_1ST = 10,

    MAX_ZOOM_IN_FACTOR_FOR_2ND = 1,
    MAX_ZOOM_OUT_FACTOR_FOR_2ND = 16,

    MAX_ZOOM_IN_FACTOR_FOR_3RD = 10,
    MAX_ZOOM_OUT_FACTOR_FOR_3RD = 10,

    MAX_ZOOM_IN_FACTOR_FOR_4TH = 8,
    MAX_ZOOM_OUT_FACTOR_FOR_4TH = 16,
} SOURCE_BUFFER_ZOOM_FACTOR_LIMIT;

typedef enum
{
    MAIN_BUFFER_ID = 0,
    PREVIEW_A_BUFFER_ID = 1,
    PREVIEW_B_BUFFER_ID = 2,
    PREVIEW_C_BUFFER_ID = 3,
    PREVIEW_BUFFER_TOTAL_NUM,
} CAPTURE_BUFFER_ID;


int sgks_mpi_sys_Init(sgks_mpi_init_s *mpi_init_param);
int sgks_mpi_sys_GetDriverHandle(sgks_mpi_manager_s *mpi);
int sgks_mpi_sys_cmd_RgbGainDefault(sgks_mpi_manager_s *mpi);
int sgks_mpi_sys_cmd_CapturePreviewBufferSetup(sgks_mpi_manager_s *mpi);
int sgks_mpi_sys_Cmd_SetupInfo(sgks_mpi_manager_s *mpi);
int sgks_mpi_sys_Cmd_VideoSystemSetup(sgks_mpi_manager_s *mpi);
int sgks_mpi_sys_setup_Info();
int sgks_mpi_sys_SetupIRQ(sgks_mpi_manager_s *mpi);
int sgks_mpi_sys_SendDefaultCmd(sgks_mpi_manager_s *mpi);
int sgks_mpi_sys_BootFw(sgks_mpi_manager_s *mpi);
int sgks_mpi_sys_ReadFileToMem(char *filename, u8 *addr, u32 size);
int sgks_mpi_sys_DumpMemToFile(char *filename, u8 *addr, u32 size);
int sgks_mpi_sys_Start();
int sgks_mpi_sys_PreViewInit(sgks_preview_config_s *preview_config);
int sgks_mpi_sys_deinit();
int sgks_mpi_sys_GetMpiHandle();
int sgks_mpi_sys_GetDspStats(sgks_mpi_dsp_status_s *dsp_status);
int sgks_mpi_sys_GetStats(u8 *status);
int sgks_mpi_mdi_cmd(u32 cmd, u8 *arg);
int sgks_mpi_sys_GetModuleInitStatus(sgks_mpi_manager_s *mpi, sgks_mpi_module_id_e module_id);
int sgks_mpi_sys_UpdateModuleInitStatus(sgks_mpi_manager_s *mpi, sgks_mpi_module_id_e module_id, sgks_mpi_module_init_status_e module_status);
inline int sgks_mpi_sys_ConfigCvbsDma(int en);

#ifdef  __cplusplus
}
#endif

#endif


